<?php
require_once ("../utils/ConnectionFactory.php");
require_once ("../persistance/data/TypeArticleDO.php");

/**
 *
 * CRUD de la classe TypeArticleDAO
 * @author Quentin Laujac, Charles Hurtevent
 *
 */
class TypeArticleDAO{
	
	/**
	 * retourne un typeArticleDO en fonction du codeTypeArticle
	 */
	public function getTypeArticleDOByCodeTypeArticle($codeTypeArticle) {
		$connection = ConnectionFactory::getConnection ();
		$reponse = $connection->query ( "SELECT * FROM type_art WHERE code_type_art = '" . $codeTypeArticle."'" );

		if ($reponse == null || $reponse->rowCount () == 0) {
			return null;
		}
		
		$donnee = $reponse->fetch ();
		$typeArticleDO = $this->setTypeArticleDO($donnee);
		return $typeArticleDO;
	}

	private function setTypeArticleDO($donnee){
		$typeArticleDO = new TypeArticleDO();
		$typeArticleDO->setGetCodeTypeArticle($donnee['code_type_art']);
		$typeArticleDO->setlibelle($donnee['libelle']);
		
		return $typeArticleDO;
	}
}